package com.itms.tool.data;

import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class Category {

	public static final String PARENT = "parent_category_id";
	
	@DatabaseField(id = true)
	private int id;
	@DatabaseField
	private String name;
	@DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = PARENT)
	private Category parentCategory;
	@ForeignCollectionField
	private ForeignCollection<Category> subCategories;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Category getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	public ForeignCollection<Category> getSubCategories() {
		return subCategories;
	}

	@Override
	public int hashCode() {
		return 31 * id;
	}
	
	@Override
	public boolean equals(java.lang.Object o) {
		if (!(o instanceof Category)) {
			return false;
		}
		return id == ((Category)o).id;
	}
	
	@Override
	public String toString() {
		return "Category[id=" + id + ",name=" + name + 
				(parentCategory != null ? "parent=" + parentCategory : "") + "]";
	}
}
